//
//  UserCardTable.m
//  blackjack
//
//  Created by Thi Nguyen Tran on 3/24/10.
//  Copyright 2010 Epsilon. All rights reserved.
//

#import "UserCardTable.h"

#define START_POS_X		33
#define START_POS_Y		20
#define BTN_WIDTH		58
#define BTN_HEIGHT		67

@implementation UserCardTable

@synthesize delegate;


- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        UIImage *img = [UIImage imageNamed:@"basic_user_num.png"];
		[self setImage:img];
    }
    return self;
}

- (void)touchesBegan:(NSSet *)touches 
		   withEvent:(UIEvent *)event {
	[self setUserInteractionEnabled:NO];
	UITouch * touch = [touches anyObject];
	CGPoint point = [touch locationInView:[touch view]];
	int i = (point.x - START_POS_X) / BTN_WIDTH;
	int j = (point.y - START_POS_Y) / BTN_HEIGHT;
	int res = i + j * 4;
	if(res >= 0 && res < 28 && i >= 0 && j >= 0) {
		[delegate chooseValueForUser:res];
	}
	else {
		[delegate chooseValueForUser:-1];
	}
}


- (void)dealloc {
    [super dealloc];
}


@end
